var t = getApp();

Page({
    data: {
        recipientId: "",
        changeIntegral: "",
        actualIntegral: 0,
        integral: 0,
        loading: !1,
        integral_name: "",
        love_name: "",
        checkRadio: "1",
        shiftPoint: !1,
        nickname: "",
        timerId: null
    },
    onLoad: function(t) {
        "shift" == t.type && this.setData({
            shiftPoint: !0
        }), this._getData();
    },
    onReady: function() {},
    onChange: function(t) {
        this.setData({
            checkRadio: t.detail
        });
    },
    onShow: function() {
        this.data.isclick = !0;
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    idChange: function(t) {
        var a = this, e = t.detail;
        this.setData({
            recipientId: e
        }), this.data.timerId && clearTimeout(this.data.timerId), this.data.timerId = setTimeout(function() {
            a.getNickName();
        }, 800);
    },
    getNickName: function() {
        var a = this;
        if (this.data.recipientId) {
            var e = t.getNetAddresss("member.member.memberInfo");
            t._getNetWork({
                url: e,
                data: {
                    uid: this.data.recipientId
                },
                success: function(t) {
                    1 === t.data.result ? a.setData({
                        nickname: t.data.data.nickname
                    }) : a.setData({
                        nickname: ""
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    integralChange: function(t) {
        var a = t.detail;
        if (/^[0-9]+.?[0-9]*$/.test(a)) {
            var e, n = this.data.info;
            e = this.data.shiftPoint ? Number(a) / n.point_transformation_amount * n.point_transformation_ratio : Number(a) / n.transformation_amount * n.transformation_ratio, 
            this.setData({
                changeIntegral: a,
                actualIntegral: e || 0
            });
        } else this.setData({
            changeIntegral: ""
        }), wx.showToast({
            title: "只能输入数字",
            icon: "none"
        });
    },
    _getData: function() {
        var a = this, e = t.getNetAddresss("plugin.integral.Frontend.Controllers.Page.transfer-love");
        t._getNetWork({
            url: e,
            success: function(t) {
                1 === t.data.result ? (a.setData({
                    integral: t.data.data.member_integral,
                    integral_name: t.data.data.integral_name,
                    love_name: t.data.data.love_name,
                    info: t.data.data
                }), wx.setNavigationBarTitle({
                    title: a.data.shiftPoint ? "转化".concat(t.data.data.point_name) : "转化".concat(t.data.data.love_name)
                })) : console.log(t.data.msg);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    sureChange: function() {
        var a = this;
        if (this.setData({
            loading: !0
        }), 2 == this.data.checkRadio && "" == this.data.nickname) return wx.showToast({
            title: "该会员不存在",
            icon: "none",
            duration: 1500
        }), void this.setData({
            loading: !1
        });
        if (!this.data.changeIntegral || "" == this.data.changeIntegral.trim()) return wx.showToast({
            title: "请输入转化数额",
            icon: "none",
            duration: 1500
        }), void this.setData({
            loading: !1
        });
        if ((!this.data.recipientId || "" == this.data.recipientId.trim()) && "2" == this.data.checkRadio) return wx.showToast({
            title: "请输入受让人ID",
            icon: "none",
            duration: 1500
        }), void this.setData({
            loading: !1
        });
        if (Number(this.data.changeIntegral) > Number(this.data.integral)) return wx.showToast({
            title: "输入的".concat(this.data.changeIntegral, "数额超过已有的").concat(this.data.integral),
            icon: "none"
        }), void this.setData({
            loading: !1
        });
        var e, n = {
            change_value: this.data.changeIntegral,
            recipient_id: this.data.recipientId,
            give_type: this.data.checkRadio
        };
        e = this.data.shiftPoint ? t.getNetAddresss("plugin.integral.Frontend.Modules.Integral.Controllers.Transfer.point-transformation") : t.getNetAddresss("plugin.integral.Frontend.Modules.Integral.Controllers.Transfer.love-transformation"), 
        t._getNetWork({
            url: e,
            data: n,
            success: function(t) {
                a.setData({
                    loading: !1
                }), 1 === t.data.result ? wx.showToast({
                    title: "转化成功",
                    icon: "none",
                    duration: 1500,
                    complete: function() {
                        setTimeout(function() {
                            wx.navigateTo({
                                url: "/packageB/member/Integral_love_detail/Integral_love_detail"
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            }
        });
    }
});